package com.wx.tourism.serviceimpl;

import com.wx.tourism.mapper.CarMapper;
import com.wx.tourism.service.CarService;
import com.wx.utils.Page;
import com.wx.utils.Pageable;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by myd on 16/5/7.
 */
@Service("carServiceImpl")
public class CarServiceImpl<Car> implements CarService<Car> {

    /**
     * 注入
     */
    @Autowired
    private CarMapper<Car> carCarMapper;

    /**
     * 获取所有的数据列表
     * @param entity
     * @return
     */
    @Override
    public List<Car> getAll(Car entity) {
        return this.carCarMapper.getall(entity);
    }

    /**
     * 分页获取数据
     * @param pageable
     * @param entity
     * @return
     */
    @Override
    public Page<Car> findPage(Pageable pageable, Car entity) {
        Map<String,Object> map = new HashMap<>();
        map.put("pageable",pageable);
        map.put("car",entity);
        List<Car> list = this.getAll(entity);
        List<Car> entitys = this.carCarMapper.findpage(map);
        Page<Car> page = new Page<>();
        page.setRows(entitys);
        page.setTotalCount(entitys.size());
        page.setPage(pageable.getPage());
        page.setTotal(list.size());
        return page;
    }

    /**
     * 保存数据
     * @param entity
     * @return
     */
    @Override
    public int save(Car entity) {
        return this.carCarMapper.save(entity);
    }

    /**
     * 删除数据,支持批量删除
     * @param idList
     * @return
     */
    @Override
    public int delete(List<String> idList) {
        return this.carCarMapper.delete(idList);
    }
}
